package oss

import (
	"net/http"
	"regexp"
	"strings"
	"time"
)

// https://docs.aliyun.com/#/pub/oss/product-documentation/intruduction&concepts
func isValidBucketName(bucket string) bool {
	return regexp.MustCompile(`^[[:alnum:]](\w|\-){1,253}[[:alnum:]]$`).MatchString(bucket)
}

func isValidObjectName(object string) bool {
	byteLen := len([]byte(object))
	if byteLen > 1023 || byteLen < 1 {
		return false
	}

	if strings.HasPrefix(object, "\\") || strings.HasPrefix(object, "/") {
		return false
	}
	return true
}

func isValidLocation(bucketLocation string) bool {
	for _, location := range BucketLocations {
		if location == bucketLocation {
			return true
		}
	}
	return false
}

func isValidPermission(permission string) bool {
	for _, p := range BucketPermissions {
		if p == permission {
			return true
		}
	}
	return false
}

func getGmtDateOnNow() string {
	now := time.Now()
	gmtTime := now.Format(http.TimeFormat)
	return gmtTime
}
